﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class CX_HuListControl : MPBasicTemplate
    {
        string pid = string.Empty;
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        CustomGridView CustomGridList1;
        TextBox 房屋坐落, 姓名;
        protected override void OnLoad(EventArgs e)
        {
            CustomGridList1 = (CustomGridView)FindControl("CustomGridList1");
            房屋坐落 = (TextBox)FindControl("房屋坐落");
            姓名 = (TextBox)FindControl("姓名");
            if (!base.Page.IsPostBack)
            {
                BindData();
            } 
            CustomGridList1.OnLoadData+=new EventHandler(CustomGridList1_OnLoadData);
        }
        protected void BindData()
        {
            CustomGridList1.RowDataBound += new GridViewRowEventHandler(CustomGridList1_RowDataBound);
            string strPId = base.Page.Request["PID"];
            if (!string.IsNullOrEmpty(strPId))
            {
                string strWhere = string.Empty;
                if (!string.IsNullOrEmpty(房屋坐落.Text.Trim())) 
                {
                    strWhere += " and 房屋坐落 like '%" + 房屋坐落.Text.Trim() + "%'";
                }
                if (!string.IsNullOrEmpty(姓名.Text.Trim()))
                {
                    strWhere += " and (产权人 like '%" + 姓名.Text.Trim() + "%' or 承租人 like '%" + 姓名.Text.Trim() + "%')";
                }
                string sql = string.Format("Select n.Id,n.房屋坐落,n.产权人 所有权人,n.承租人 From Zs_Zsperson n Where 1 = 1 And (Pid = '{0}' Or Id In (Select Zspid From Zs_Zzbcjfenhu Where Pid In (Select Id From Zs_Prono Where Pid = '{0}')))", strPId);
                sql += strWhere;
                sql += "";
                DataTable dt = _EluZSDataProvider.GetTable(sql);
                CustomGridList1.DataSource = dt;
                CustomGridList1.RecordCount = dt.Rows.Count;
                CustomGridList1.DataBind();
            }
        }
        protected void CustomGridList1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView rowview = (DataRowView)e.Row.DataItem;
                string strId = rowview["ID"].ToString();
                string strPId = base.Page.Request["PID"];
                if (!string.IsNullOrEmpty(strPId))
                {
                    Literal 补偿面积 = (Literal)e.Row.FindControl("补偿面积");
                    Literal 补偿款 = (Literal)e.Row.FindControl("补偿款");
                    Literal 评估报告 = (Literal)e.Row.FindControl("评估报告");
                    Literal 补偿协议 = (Literal)e.Row.FindControl("补偿协议");

                    Literal 协议提交 = (Literal)e.Row.FindControl("协议提交");
                    Literal 协议备案 = (Literal)e.Row.FindControl("协议备案");
                    Literal 资金划转 = (Literal)e.Row.FindControl("资金划转");
                    Literal 补偿决定 = (Literal)e.Row.FindControl("补偿决定");
                    Literal 司法强制 = (Literal)e.Row.FindControl("司法强制");

                    补偿面积.Text = _EluZSDataProvider.GetString(@"Select Nvl(To_Number(Nvl(Replace(Textbox73, '\', ''), 0)),0)
             From Zs_Hbhxy t
            Where t.Personid = '" + strId + @"'
              And Pnid =
(Select Id From Zs_Prono Where Pid = '" + strPId + "')");
                    补偿款.Text = _EluZSDataProvider.GetString(@"Select Nvl((Select To_Number(Nvl(Replace(Textbox19, '\', ''), 0))
             From Zs_Hbhxy t
            Where t.Personid = '" + strId + @"'
              And Pnid =
                  (Select Id From Zs_Prono Where Pid = '" + strPId + @"')),
           0) + Nvl((Select To_Number(Nvl(Replace(Textbox21, '\', ''), 0))
                      From Zs_Cqzhxy t
                     Where t.Fid In (Select Id
                                       From Zs_Proloupan
                                      Where Zid In
                                            (Select Id
                                               From Zs_Prozhuang
                                              Where Pnid = '" + strPId + @"')
                                        And Zspid = '" + strId + @"')),
                    0) From dual ");
                    评估报告.Text = _EluZSDataProvider.GetString(@"Select (Case
         When (Select Count(*) From zs_zzbcjfenhu t Where zspid='" + strId + @"' And Pid In 
         (Select Id From zs_prono Where PId= '" + strPId + @"') ) > 0 Then
          '√'
         Else
          '  '
       End) From dual ");
                    补偿协议.Text = _EluZSDataProvider.GetString(@"Select (Case
         When Nvl((Select Count(*)
                    From Zs_Hbhxy t
                   Where t.Personid='" + strId + @"'
                     And Pnid =
                         (Select Id From Zs_Prono Where Pid = '" + strPId + @"')),
                  0) + Nvl((Select Count(*)
                             From Zs_Cqzhxy
                            Where Fid In (Select Id
                                            From Zs_Proloupan
                                           Where Zid In
                                                 (Select Id
                                                    From Zs_Prozhuang
                                                   Where Pnid = '" + strPId + @"')
                                             And Zspid = '" + strId + @"')),
                           0) > 0 Then
          '√'
         Else
          '  '
       End) From dual ");
                    协议提交.Text = _EluZSDataProvider.GetString(@"Select (Case
         When Nvl((Select Count(*)
                    From Zs_Hbhxy t
                   Where t.Personid='" + strId + @"' and 审核状态=1 
                     And Pnid =
                         (Select Id From Zs_Prono Where Pid = '" + strPId + @"')),
                  0) + Nvl((Select Count(*)
                             From Zs_Cqzhxy
                            Where 审核状态=1 and Fid In (Select Id
                                            From Zs_Proloupan
                                           Where Zid In
                                                 (Select Id
                                                    From Zs_Prozhuang
                                                   Where Pnid = '" + strPId + @"')
                                             And Zspid = '" + strId + @"')),
                           0) > 0 Then
          '√'
         Else
          '  '
       End) From dual ");
                    协议备案.Text = _EluZSDataProvider.GetString(@"Select (Case
         When Nvl((Select Count(*)
                    From Zs_Hbhxy t
                   Where t.Personid='" + strId + @"' and 提交备案 = 1
                     And Pnid =
                         (Select Id From Zs_Prono Where Pid = '" + strPId + @"')),
                  0) + Nvl((Select Count(*)
                             From Zs_Cqzhxy
                            Where 提交备案 = 1 and Fid In (Select Id
                                            From Zs_Proloupan
                                           Where Zid In
                                                 (Select Id
                                                    From Zs_Prozhuang
                                                   Where Pnid = '" + strPId + @"')
                                             And Zspid = '" + strId + @"')),
                           0) > 0 Then
          '√'
         Else
          '  '
       End) From dual ");
                    资金划转.Text = _EluZSDataProvider.GetString(@"Select Case When (Select Count(Id) From zs_change_money Where zspid Like '%" + strId + @"%' And bid In (Select Id From zs_bcbasicinfo Where pnid ='" + strPId + @"'))>0 Then '√' Else '  ' End From dual ");
                    补偿决定.Text = _EluZSDataProvider.GetString(@"Select Case When (Select Count(IID) From st_instance Where wid In (
Select wid From st_workflow Where wname ='房屋征收补偿决定')
And iid In (Select iid From xt_instance_ext Where 关联ID In (
Select Id From zs_zzbcjfenhu Where zspid='" + strId + @"' And PID In (
Select Id From zs_prono Where pid='" + strPId + @"'))))>0 Then '√' Else '  ' End From dual ");
                    司法强制.Text = _EluZSDataProvider.GetString(@"Select Case When (Select count(Distinct Id) From ZS_QZZXXX Where caseid In (
Select caseid From zs_case_register Where iid In (
Select IID From st_instance Where wid In (
Select wid From st_workflow Where wname ='房屋征收补偿决定')
And iid In (Select iid From xt_instance_ext Where 关联ID In (
Select Id From zs_zzbcjfenhu Where zspid='" + strId + @"' And PID In (
Select Id From zs_prono Where pid='" + strPId + @"'))))) 
)>0 Then '√' Else '  ' End From dual ");
                }
            }
        }
        protected void CustomGridList1_OnLoadData(object sender, EventArgs e)
        {
            BindData();
        }

    }
}
